package com.acegear.horizon.domain.models.jpa;

import com.fasterxml.jackson.annotation.JsonIgnore;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;

/**
 * Created by wangsike on 2017/1/14.
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(indexes = @Index(columnList = "eventId"))
public class ClubEventQA {
    @Column
    private Long eventId;

    @Column(unique = true)
    private Long eventQAId;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @JsonIgnore
    private Long id;

    @Column
    private Long askUserId;

    @Column(columnDefinition = "TEXT")
    private String question;

    @Column(columnDefinition = "TEXT")
    private String answer;

    @Column
    private Boolean answered;

    @CreatedDate
    @Column
    private Long createAt;

    @LastModifiedDate
    @Column
    private Long updateAt;

    public ClubEventQA() {
    }

    public ClubEventQA(Long eventId, Long eventQAId, Long askUserId, String question, String answer) {
        this.eventId = eventId;
        this.eventQAId = eventQAId;
        this.askUserId = askUserId;
        this.question = question;
        this.answer = answer;
        answered = answer != null && !answer.isEmpty();
    }

    public Long getEventId() {
        return eventId;
    }

    public void setEventId(Long eventId) {
        this.eventId = eventId;
    }

    public Long getEventQAId() {
        return eventQAId;
    }

    public void setEventQAId(Long eventQAId) {
        this.eventQAId = eventQAId;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getAskUserId() {
        return askUserId;
    }

    public void setAskUserId(Long askUserId) {
        this.askUserId = askUserId;
    }

    public String getQuestion() {
        return question;
    }

    public void setQuestion(String question) {
        this.question = question;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        if (this.answer == null || this.answer.isEmpty()) setAnswered(true);
        this.answer = answer;
    }

    public Boolean getAnswered() {
        return answered;
    }

    public void setAnswered(Boolean answered) {
        this.answered = answered;
    }

    public Long getCreateAt() {
        return createAt;
    }

    public Long getUpdateAt() {
        return updateAt;
    }
}
